package com.sky.mapper;

import com.sky.annotation.AutiFill;
import com.sky.dto.EmployeeEditPasswordDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    @Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user)" +
            " values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutiFill(value = OperationType.INSERT)
    void insert(Employee employee);

    //员工分页查询
    Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);

    /*根据组件动态修改*/
    @AutiFill(value = OperationType.UPDATE)
    void update(Employee employee);

    @Select("select * from employee where id=#{id}")
    Employee findById(Long id);

    //根据id查询密码
    @Select("select password from employee where id=#{id}")
    String PasswordById(Long id);

    /*修改密码*/
    @Update("update employee set password=#{newPassword} where id=#{id}")
    void editPassword(EmployeeEditPasswordDTO employeeEditPasswordDTO);
}
